home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxlibs / sblib / ex3.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-12  |  2.9 KB  |  131 lines

  1. /*Example 3.
  2.   Jouer un fichier .voc
  3.   Play from a voc file.
  4.  
  5. */
  6.  
  7. /* Include pour C++ */
  8. #include <sys\stat.h>
  9. #include <fcntl.h>
  10. #include <io.h>
  11. #include <stdlib.h>
  12. #include <dir.h>
  13. #include <stdio.h>
  14. #include <conio.h>
  15.  
  16. /* Include pour la librairie. */
  17. /* Include for library. */
  18. #include "type.h"
  19. #include "sbdsp.h"
  20. #include "status.h"
  21.  
  22. /*
  23.   Fonction KbHit. Verifie si une touche a ete pesee.
  24.   retourne 0 si une touche est pesee,
  25.   retourne 1 si aucune touche pesee.
  26.   --
  27.   KbHit Function. Check for a key press.
  28.   return 0 if a key pressed,
  29.   otherwise 1.
  30.  
  31. */
  32. int KbHit( void )
  33. {
  34.    int retour = 1;
  35.  
  36.    asm mov ah,1;
  37.    asm int 016h;
  38.    if( (_FLAGS & 64) == 64 )
  39.       retour = 0;
  40.  
  41.    return retour;
  42. }
  43.  
  44.  
  45. /*
  46.   Fonction PrintCardInfo. Affiche les informations contenues
  47.   dans la structure stc_CARD_INFO.
  48.   ---
  49.   PrintCardInfo functions. Display stc_CARD_INFO
  50.  
  51. */
  52. void PrintCardInfo( stc_CARD_INFO *card )
  53. {
  54.  
  55.    printf("   Card Info.");
  56.    printf("\n\r   ----------");
  57.  
  58.  
  59.    printf("\n\n\n\rCard Name:%s",card->cardName);
  60.    printf("\n\rI/O port:%x",card->ioPort);
  61.    printf("\n\rIRQ     :%u",card->irq);
  62.    printf("\n\r8 bits dma:%u",card->dmaChanel8);
  63.    if( card->dmaChanel16 != sta_NOT_DEFINED )
  64.       printf("\n\r16 bits dma:%u",card->dmaChanel16);
  65.    else
  66.       printf("\n\r16 bits dma:N/A");
  67.    printf("\n\rDSP version:%u.%u",card->dspMaj, card->dspMin);
  68.    printf("\n\rCurrent Sampling rate:%u",card->samplingRate);
  69.    printf("\n\rMinimum Sampling rate:%u",card->minSamplingRate);
  70.    printf("\n\rMaximum Sampling rate:%u",card->maxSamplingRate);
  71.    getch();
  72.  
  73.  
  74. }
  75.  
  76.  
  77. main()
  78. {
  79.    SB_DSP dsp;
  80.    int handle;
  81.    unsigned flagFin = 0;
  82.  
  83.  
  84.    clrscr();
  85.    /* Ouverture du fichier .voc */
  86.      /* Voc file open */
  87.    handle = open("sound.voc",O_RDONLY | O_BINARY,S_IREAD);
  88.  
  89.    if( dsp.Set8BitsDma(1) == err_VALID_DMA )
  90.    {
  91.       if( dsp.SetIOPort(0x220) == err_VALID_PORT )
  92.       {
  93.      if( dsp.SetIrq(5) == err_VALID_IRQ )
  94.      {
  95.         if( dsp.InitCard() == err_INIT_DONE )
  96.         {
  97.            if( dsp.SetOutputVocHandle(handle) == err_VALID_HANDLE )
  98.            {
  99.           /* Donne l'adresse du flag qui
  100.              nous indiquera la fin du playback.
  101.              ---------------------------------- */
  102.  
  103.           /* Set flag address.
  104.              ----------------- */
  105.  
  106.           dsp.SetUserFlag(&flagFin);
  107.           PrintCardInfo(dsp.GetCardInfo());
  108.  
  109.           /* On fait jouer le fichier jusqu'a la fin
  110.              ou jusqu'a ca qu'une touche soit peser.
  111.              --------------------------------------- */
  112.           dsp.Start();
  113.           while( !KbHit() && (flagFin == 0) );
  114.           dsp.Stop();
  115.            }
  116.            else
  117.           printf("Handle de fichier invalide.");
  118.         }
  119.         else
  120.            printf("Pas de carte trouve.");
  121.      }
  122.      else
  123.         printf("Invalide IRQ pour cette carte");
  124.       }
  125.       else
  126.      printf("Invalide IO port pour cette carte");
  127.    }
  128.    else
  129.       printf("Canal DMA 8 bits invalide pour cette carte");
  130.    close(handle);
  131. }